//
//  WUPriveViewController.m
//  Home
//
//  Created by 吴军虎吴军虎 on 16/5/6.
//  Copyright © 2016年 LanJue. All rights reserved.
//

#import "WUPriveViewController.h"
#import "WUHeadCollectionCell.h"
#include "WUPageNameCell.h"
#import "WUPageHeightCell.h"
#import "WUPageWorkCell.h"
#import "WUPageTeachCell.h"
#import "UIView+Five.h"
#import "YHYEditHomePageViewController.h"//添加任务
//#import "YHYDesignerPersonViewController.h"//我的主页 个人信息
#import "YHYDesignerPersonController.h"
#import "YHYDesignerPersonViewController.h"
#import "YHYEditingPersonViewController.h"
@interface WUPriveViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>
{

    ResignModel *model;
}

@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) WSCustomButton *shareBtn;
@property (nonatomic, strong) WSCustomButton *backBtn;
@property (nonatomic, assign) BOOL isSelect;
@property (nonatomic,assign)BOOL isON;/**<点击沟通*/
@property (nonatomic,retain)UIView *alertView;
@property (nonatomic,assign)BOOL isSelrct;


@end

@implementation WUPriveViewController

//- (void)viewWillAppear:(BOOL)animated {
//    
//    self.navigationController.navigationBarHidden = NO;
//    self.title = @"个人主页";
//    self.tabBarController.tabBar.hidden = YES;
//}
//- (void)viewWillDisappear:(BOOL)animated{
//    self.tabBarController.tabBar.hidden = NO;
//}

- (void)viewWillAppear:(BOOL)animated {
    
    //    self.navigationController.navigationBarHidden = NO;
    self.title = @"个人主页";
    self.tabBarController.tabBar.hidden = YES;
    //  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(change:) name:@"arr" object:nil];
    self.tabBarController.tabBar.hidden=YES;
    
    self.navigationController.navigationBar.translucent = NO;
    
    // [self.myCollectionView reloadData];
}

-(void) viewWillDisappear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden=NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self getHttpUrl];
    
    self.view.backgroundColor=  LV;
    _isSelect = YES;
    [self creatView];
    _isSelrct = NO;
    _isON = NO;
    
    //编辑
    UIButton *bottonView = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50 * AUTO_WIDTH)];
    bottonView.backgroundColor=[UIColor whiteColor];
    [bottonView setTitle:@"编辑个人主页" forState:UIControlStateNormal];
    [bottonView setTitleColor:GH forState:UIControlStateNormal];
    [bottonView setImage:[UIImage imageNamed:@"jj"] forState:UIControlStateNormal];
    [bottonView addTarget:self action:@selector(bottonAction:) forControlEvents:UIControlEventTouchUpInside];
    bottonView.titleLabel.font=[UIFont fontWithName:TFont size:TEXTCONTENTFONT *AUTO_WIDTH];
    [self.view addSubview:bottonView];
    [bottonView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 50 * AUTO_WIDTH));
        make.left.bottom.mas_equalTo(@0);
    }];
    
    UIView *line = [UIView new];
    line.backgroundColor = [UIColor lightGrayColor];
    [bottonView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(bottonView.mas_top);
        make.height.mas_equalTo(0.5 * AUTO_HEIGHT);
        make.width.mas_equalTo(bottonView);
        make.left.mas_equalTo(bottonView.mas_left);
        
    }];

    
    
    UIImageView *viewIV = [UIImageView new];
    viewIV.image = [UIImage imageNamed:@"purse_shadow"];
    //viewIV.backgroundColor = [UIColor redColor];
    [self.view addSubview:viewIV];
    
    [viewIV mas_makeConstraints:^(MASConstraintMaker *make) {
        //        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 100 * AUTO_WIDTH));
        make.left.bottom.mas_equalTo(@0);
        //make.left.mas_equalTo(self.view);
        make.right.mas_equalTo(self.view);
        make.height.mas_equalTo(60 * AUTO_HEIGHT);
        
    }];
    
}




- (void)creatView{
    
    self.backBtn = [WSCustomButton buttonWithType:UIButtonTypeCustom];
    self.backBtn.frame = CGRectMake(0, 0, 30, 30);
    [self.backBtn setImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
    [self.backBtn addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_backBtn];
    
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.sectionInset = UIEdgeInsetsMake(5 * AUTO_WIDTH, 0, 0 * AUTO_WIDTH, 0);
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT -114*AUTO_HEIGHT) collectionViewLayout:flowLayout];
    
    flowLayout.minimumLineSpacing =8 * AUTO_HEIGHT;
    self.collectionView.backgroundColor = LV;
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    [self.view addSubview:self.collectionView];
    
    [_collectionView registerClass:[WUHeadCollectionCell class] forCellWithReuseIdentifier:@"WUHeadCollectionCell"];
    
    [_collectionView registerClass:[WUPageNameCell class] forCellWithReuseIdentifier:@"WUPageNameCell"];
    
    [_collectionView registerClass:[WUPageHeightCell class] forCellWithReuseIdentifier:@"WUPageHeightCell"];
    
    [_collectionView registerClass:[WUPageWorkCell class] forCellWithReuseIdentifier:@"WUPageWorkCell"];
    
    [_collectionView registerClass:[WUPageTeachCell class] forCellWithReuseIdentifier:@"WUPageTeachCell"];
    
    [_collectionView reloadData];
    
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    
    if (_isSelect == YES) {
        return 5;
    }
    else if (_isSelect == NO){
        return 5 + 3;
        //  [_collectionView reloadData];
    }
    return 0;
    
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.row ==0) {
        
        return CGSizeMake(self.collectionView.frame.size.width, 80 *AUTO_WIDTH);
        
    }else if (indexPath.row == 1) {
        
        return CGSizeMake(SCREEN_WIDTH - (8 * AUTO_WIDTH * 2), 125.00 * AUTO_WIDTH);
        
    } else if (indexPath.row == 2){
        
        return CGSizeMake(SCREEN_WIDTH - (8 * AUTO_WIDTH * 2), 140.00 * AUTO_WIDTH);
        
    }else if (indexPath.row == 3) {
        
        return CGSizeMake(SCREEN_WIDTH - (8.00 * AUTO_WIDTH * 2), 140 * AUTO_HEIGHT);
    }
    
    else if (indexPath.row == 4) {
        
        return CGSizeMake(SCREEN_WIDTH - (8.00 * AUTO_WIDTH * 2), 110.00 * AUTO_WIDTH );
    }
    else {
        
        return CGSizeMake(SCREEN_WIDTH - (8 * AUTO_WIDTH * 2), 410.00 * AUTO_WIDTH);
    }
    
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row ==0) {
        
        static NSString *head=@"WUHeadCollectionCell";
        WUHeadCollectionCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:head forIndexPath:indexPath];
        [cell settingRegisnModel:model];
        
        return cell;
    }
    
    if (indexPath.row == 1) {
        
        static NSString *name = @"WUPageNameCell";
        WUPageNameCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:name forIndexPath:indexPath];
        model.sex = self.sex;
        model.name = self.name;
        model.headpic = self.headerImage;
        [cell settingRegisnModel:model];

        return cell;
    }
    if (indexPath.row == 2) {
        static NSString *str = @"WUPageHeightCell";
        WUPageHeightCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:str forIndexPath:indexPath];
        [cell settingRegisnModel:model];

        return cell;
    }
    if (indexPath.row == 3) {
        
        static NSString *str = @"WUPageWorkCell";
        WUPageWorkCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:str forIndexPath:indexPath];
        [cell settingRegisnModel:model];

        return cell;
    }
    else  {
        
        static NSString *str = @"WUPageTeachCell";
        WUPageTeachCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:str forIndexPath:indexPath];
        [cell settingRegisnModel:model];

        return cell;
        
    }
    
    // return nil;
}


- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    //    if (indexPath.row == 5) {
    //        NSLog(@"fsd");
    //    }
    
}


- (void)backAction:(UIButton *)back{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void) chuangjianActon:(UIButton *) btn
{
    NSLog(@"创建微简历创建微简历");
}

-(void) quxiaoAction:(UIButton*) btn
{
    self.alertView.alpha=0;
}

-(void) bottonAction:(UIButton *) btn
{
     YHYEditingPersonViewController *edit=[[YHYEditingPersonViewController alloc]init];
    edit.Mymodel = model;
    [self.navigationController pushViewController:edit animated:YES];

}
-(void)getHttpUrl{

    NSString * url_string = [NSString stringWithFormat:@"%@%@",JIAFANURL,@"Gafaer/Home/myHome"];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = HTTPSET;
    
    [manager GET:url_string parameters:@{@"uid":[LOCALSEVE objectForKey:@"UID"],@"mcode":[LOCALSEVE objectForKey:@"MCODE"]} success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        model = [ResignModel new];
        [model setValuesForKeysWithDictionary:[responseObject objectForKey:@"data"]];
        [self.collectionView reloadData];
        NSLog(@"个人主页：%@",responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        NSLog(@"error:%@",error);
        
    }];

}
@end
